const fs = require('fs');
const express = require('express');
const bodyParser = require('body-parser');
const router = express.Router();
const app = express();
const refreshToken = require('../wx_server/getWebToken');
refreshToken()

const getJsApiData = require('../wx_server/getJsApiData')

app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());

/* GET users listing. */
router.get('/', function(req, res)  {
    const currentToken = fs.readFileSync('./token').toString();
    const currentTicket = fs.readFileSync('./ticket').toString();
    console.log('ticket '  + currentTicket)
    var clientUrl =  decodeURIComponent(req.query.url);
    setTimeout(function () {
        var apidata = getJsApiData(clientUrl,currentToken,currentTicket)
        res.jsonp({signature: apidata[0], timestamp: apidata[1], noncestr: apidata[2], appId: 'wxd83a71485c5ba584'});
    },1000)
})

module.exports = router;